/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPlaceRegisterDialog.java
 *
 * Created on 2009-9-4, 14:16:36
 */

package cn.ekuma.epos.grogshop;

import cn.ekuma.data.ui.swing.JEditorWarpDialog;
import cn.ekuma.epos.bean.util.SerivceHelper;
import cn.ekuma.epos.datalogic.I_DataLogicCustomers;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import cn.ekuma.swing.dialog.AbstractKeyBoardJDialog;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.JMessageDialog;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;
import com.openbravo.bean.BusinessPartner;
import com.openbravo.bean.infobean.CustomerInfo;
import com.openbravo.bean.Place;
import com.openbravo.bean.Service;
import com.openbravo.bean.Serving;
import com.openbravo.pos.customers.CustomersEditor;
import com.openbravo.pos.panels.JCustomerFinder;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Administrator
 */
public class JPlaceRegisterDialog extends AbstractKeyBoardJDialog {
    private BusinessPartner customer;
    private Place currentPlace;
    private ComboBoxValModel rantCycleStyleModel;
    private I_DataLogicCustomers dlCustomers;
    I_DataLogicSales dlSales;
    private Serving servings;
    private Service service;
    private boolean isOK;
    AppView m_App;
	private JEditorWarpDialog customerCreateDialog;

    /** Creates new form JPlaceRegisterDialog */
    public JPlaceRegisterDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal); 
    }

    /** Creates new form JTicketsBagSharedList */
    private  JPlaceRegisterDialog(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
    }


    public static JPlaceRegisterDialog newJDialog(JTicketsBagGrogShopMapKeyBoard ticketsbagshared,I_DataLogicCustomers dlCustomers,I_DataLogicSales dlSales) {
        Window window = getWindow(ticketsbagshared);
        JPlaceRegisterDialog mydialog;
        if (window instanceof Frame) {
            mydialog = new JPlaceRegisterDialog((Frame) window, true);
        } else {
            mydialog = new JPlaceRegisterDialog((Dialog) window, true);
        }
        mydialog.init(dlCustomers,dlSales,ticketsbagshared.getM_App());
        return mydialog;
    }


    public void init(I_DataLogicCustomers dlCustomers,I_DataLogicSales dlSales,AppView m_App){
        initComponents();
        this.dlCustomers=dlCustomers;
        this.dlSales=dlSales;
        this.m_App=m_App;
        isOK=false;
    }


    public boolean register(Place place,CustomerInfo customerInfo){
        if(customerInfo!=null){
            assignCustomer(customer);
            customerNoEditAble();
        }
        currentPlace=place;
        try {
            service = dlSales.findService(Service.SERVICETYPE_place, place.getId());
        } catch (BasicException ex) {
             JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.ghogShop.placeServiceNoDefined")));
            return false;
        }
        servings=new Serving(service,0);
        servings.setM_sId(UUID.randomUUID().toString());
        servings.setM_sName(SerivceHelper.printServiceName(service));
        printState();
        this.setVisible(true);
        return isOK;
    }

    public boolean detail(Place place,BusinessPartner cust,Serving serv){
        currentPlace=place;
        this.customer=cust;
        this.servings=serv;
        customerNoEditAble();
        servinsNoEditAble();
        printState();
        this.setVisible(true);
        return isOK;
    }

    //如果是预定输入的，测应确保其信息不被修改。
    private void customerNoEditAble(){
        
    }

    //明细模式，服务相关项不能被修改
    private void servinsNoEditAble(){

    }

    //刷新相关编辑框的值
    private void printState(){

    }

    public BusinessPartner getCustomer(){
        return customer;
}

    public Serving getServings(){
       return servings;
    }

     private void addNewCustomer() {
           if(customerCreateDialog==null)
         		 customerCreateDialog=JEditorWarpDialog.getInstance(this).init(dlSales,new CustomersEditor(dlSales, new DirtyManager()));
         	 try {
      			customerCreateDialog.activate();
      		} catch (BasicException e) {
      			JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.notactive"), e));
                 return;
      		}
         	 customerCreateDialog.writeValueInsert(null);
         	 if(customerCreateDialog.getRetObj()!=null){
         		 customer=(BusinessPartner) customerCreateDialog.getRetObj();
                 printState();
              }
     }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jcmdOK = new javax.swing.JButton();
        jcmdCancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jrantPrice = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jexemptDate = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jcyclePrice = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jrantCycleStyle = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jcustomDate = new javax.swing.JTextField();
        jm_dStartDateLabel = new javax.swing.JLabel();
        jrantData = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jpriceRate = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jcustomer = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        m_jName = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        m_jTaxID = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtCard = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        m_jSearchkey = new javax.swing.JTextField();
        m_jEnter1 = new javax.swing.JButton();
        m_jEnter = new javax.swing.JButton();
        m_jEnter2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtCurdebt = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jcmdOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
        jcmdOK.setText(AppLocal.getIntString("Button.OK")); // NOI18N
        jcmdOK.setEnabled(false);
        jcmdOK.setFocusPainted(false);
        jcmdOK.setFocusable(false);
        jcmdOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
        jcmdOK.setRequestFocusEnabled(false);
        jcmdOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmdOKActionPerformed(evt);
            }
        });
        jPanel3.add(jcmdOK);

        jcmdCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
        jcmdCancel.setText(AppLocal.getIntString("Button.Cancel")); // NOI18N
        jcmdCancel.setFocusPainted(false);
        jcmdCancel.setFocusable(false);
        jcmdCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
        jcmdCancel.setRequestFocusEnabled(false);
        jcmdCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmdCancelActionPerformed(evt);
            }
        });
        jPanel3.add(jcmdCancel);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(259, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("租金设置"));
        jPanel4.setLayout(null);

        jLabel4.setText(AppLocal.getIntString("label.rantPrice")); // NOI18N
        jPanel4.add(jLabel4);
        jLabel4.setBounds(20, 30, 42, 15);

        jrantPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jPanel4.add(jrantPrice);
        jrantPrice.setBounds(80, 30, 110, 21);

        jLabel5.setText(AppLocal.getIntString("label.exemptDate")); // NOI18N
        jPanel4.add(jLabel5);
        jLabel5.setBounds(260, 30, 96, 20);

        jexemptDate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jexemptDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jexemptDateActionPerformed(evt);
            }
        });
        jPanel4.add(jexemptDate);
        jexemptDate.setBounds(330, 30, 100, 21);

        jLabel6.setText(AppLocal.getIntString("label.cyclePrice")); // NOI18N
        jPanel4.add(jLabel6);
        jLabel6.setBounds(20, 90, 90, 15);

        jcyclePrice.setEditable(false);
        jcyclePrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jcyclePrice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcyclePriceActionPerformed(evt);
            }
        });
        jPanel4.add(jcyclePrice);
        jcyclePrice.setBounds(80, 90, 110, 21);

        jLabel8.setText(AppLocal.getIntString("label.rantCycleStyle")); // NOI18N
        jPanel4.add(jLabel8);
        jLabel8.setBounds(20, 60, 60, 15);

        jrantCycleStyle.setEditable(true);
        jrantCycleStyle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jrantCycleStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrantCycleStyleActionPerformed(evt);
            }
        });
        jPanel4.add(jrantCycleStyle);
        jrantCycleStyle.setBounds(80, 60, 110, 21);

        jLabel7.setText(AppLocal.getIntString("label.customDate")); // NOI18N
        jPanel4.add(jLabel7);
        jLabel7.setBounds(260, 60, 60, 15);

        jcustomDate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jPanel4.add(jcustomDate);
        jcustomDate.setBounds(330, 60, 100, 21);

        jm_dStartDateLabel.setText(AppLocal.getIntString("label.rantData")); // NOI18N
        jPanel4.add(jm_dStartDateLabel);
        jm_dStartDateLabel.setBounds(20, 120, 80, 15);

        jrantData.setEditable(false);
        jPanel4.add(jrantData);
        jrantData.setBounds(100, 120, 240, 21);

        jLabel16.setText(AppLocal.getIntString("label.prefRate")); // NOI18N
        jPanel4.add(jLabel16);
        jLabel16.setBounds(260, 90, 60, 20);

        jpriceRate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jpriceRate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jpriceRateActionPerformed(evt);
            }
        });
        jPanel4.add(jpriceRate);
        jpriceRate.setBounds(330, 90, 100, 21);

        jPanel1.add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("会员")));

        jcustomer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/kuser.png"))); // NOI18N
        jcustomer.setFocusPainted(false);
        jcustomer.setFocusable(false);
        jcustomer.setMargin(new java.awt.Insets(8, 14, 8, 14));
        jcustomer.setRequestFocusEnabled(false);
        jcustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcustomerActionPerformed(evt);
            }
        });

        jButton1.setText("新建");
        jButton1.setMargin(new java.awt.Insets(8, 14, 8, 14));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText(AppLocal.getIntString("label.name")); // NOI18N

        m_jName.setEditable(false);

        jLabel10.setText(AppLocal.getIntString("label.taxid")); // NOI18N

        jLabel12.setText(AppLocal.getIntString("label.card")); // NOI18N

        txtCard.setFocusable(false);
        txtCard.setRequestFocusEnabled(false);

        jLabel13.setText(AppLocal.getIntString("label.address")); // NOI18N

        txtAddress.setEditable(false);

        jLabel17.setText(AppLocal.getIntString("label.phone")); // NOI18N

        txtPhone.setEditable(false);

        jLabel14.setText(AppLocal.getIntString("label.searchkey")); // NOI18N

        m_jEnter1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter1.setFocusPainted(false);
        m_jEnter1.setFocusable(false);
        m_jEnter1.setRequestFocusEnabled(false);
        m_jEnter1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnter1ActionPerformed(evt);
            }
        });

        m_jEnter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter.setFocusPainted(false);
        m_jEnter.setFocusable(false);
        m_jEnter.setRequestFocusEnabled(false);
        m_jEnter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnterActionPerformed(evt);
            }
        });

        m_jEnter2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter2.setFocusPainted(false);
        m_jEnter2.setFocusable(false);
        m_jEnter2.setRequestFocusEnabled(false);
        m_jEnter2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnter2ActionPerformed(evt);
            }
        });

        jLabel2.setText(AppLocal.getIntString("label.curdebt")); // NOI18N

        txtCurdebt.setEditable(false);
        txtCurdebt.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(m_jTaxID, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(m_jEnter2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcustomer, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtCard)
                                    .addComponent(m_jSearchkey, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(m_jEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(m_jEnter1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(73, 73, 73))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtCurdebt, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(41, 41, 41))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(15, 15, 15))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(m_jTaxID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addGap(11, 11, 11))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jcustomer)
                                .addComponent(jButton1))
                            .addComponent(m_jEnter2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(m_jSearchkey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(txtCard, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jEnter1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jEnter)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(txtCurdebt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel1.add(jPanel5, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdOKActionPerformed

        dispose();
    }//GEN-LAST:event_jcmdOKActionPerformed

    private void jcmdCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdCancelActionPerformed

        dispose();
    }//GEN-LAST:event_jcmdCancelActionPerformed

    private void jexemptDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jexemptDateActionPerformed
        calcSubTotal();
}//GEN-LAST:event_jexemptDateActionPerformed

    private void jcyclePriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcyclePriceActionPerformed
        calcSubTotal();
}//GEN-LAST:event_jcyclePriceActionPerformed

    private void jrantCycleStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrantCycleStyleActionPerformed
        calcSubTotal();
}//GEN-LAST:event_jrantCycleStyleActionPerformed

    private void jpriceRateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jpriceRateActionPerformed
        calcSubTotal();
}//GEN-LAST:event_jpriceRateActionPerformed

    private void jcustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcustomerActionPerformed
        assignCustomer();
}//GEN-LAST:event_jcustomerActionPerformed

    private void m_jEnter1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnter1ActionPerformed

}//GEN-LAST:event_m_jEnter1ActionPerformed

    private void m_jEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnterActionPerformed

}//GEN-LAST:event_m_jEnterActionPerformed

    private void m_jEnter2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnter2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_m_jEnter2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        addNewCustomer();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void assignCustomer(){
         JCustomerFinder customerFinder=JCustomerFinder.getCustomerFinder(this, dlSales);
         if(customer!=null)
             customerFinder.search(customer);
         customerFinder.setVisible(true);
         assignCustomer(customerFinder.getSelectedCustomer());
     }

    //把概述的换为确切的
  private BusinessPartner getCustomerByCustomerInfo(CustomerInfo selectedCustomer) throws BasicException{
      customer=(BusinessPartner) dlSales.findByStringId(BusinessPartner.class,selectedCustomer.getId());
      return customer;
  }

private void assignCustomer(CustomerInfo selectedCustomer) {
       if(selectedCustomer!=null){
           jcustomer.setText(selectedCustomer.getName());
           //currentPlace.setCustomerid(selectedCustomer.getId());
       }else{
           jcustomer.setText(null);
          // currentPlace.setCustomerid(null);
       }
    }

private void calcSubTotal() {
    /**
    try {
            String rantCycleStyle = (String) rantCycleStyleModel.getSelectedKey();
            int customDate = (Integer) Formats.INT.parseValue(jcustomDate.getText(), 0);
            int exemptDate = (Integer) Formats.INT.parseValue(this.jexemptDate.getText(), 0);
            double cyclePrice = (Double) Formats.CURRENCY.parseValue(this.jcyclePrice.getText(), 0);
            double priceRate = (Double) Formats.PERCENT.parseValue(this.jpriceRate.getText(), 0);
            //Date returndate = this.currentPlace.getReturnData();
            if (returndate == null) {
                returndate = new Date();
            }
            double subTotal = 0;
            int subDays = 0;
            int rangDays = 0;
            if (Place.RANTCYCLESTYLE_everyDay.equalsIgnoreCase(rantCycleStyle)) {
                rangDays = TimeUtil.getCalendarDaysAfter( currentPlace.getRantData(),returndate);
                subDays = rangDays - exemptDate;
                if (customDate > 0) {
                    subDays = subDays / customDate;
                }
            } else if (Place.RANTCYCLESTYLE_everyWeek.equalsIgnoreCase(rantCycleStyle)) {
            } else if (Place.RANTCYCLESTYLE_moon.equalsIgnoreCase(rantCycleStyle)) {
                rangDays = TimeUtil.getCalendarMonthsAfter(currentPlace.getRantData(), returndate);
                subDays = rangDays - exemptDate;
            } else if (Place.RANTCYCLESTYLE_year.equalsIgnoreCase(rantCycleStyle)) {
                rangDays = TimeUtil.getCalendarYearsAfter(currentPlace.getRantData(), returndate);
                subDays = rangDays - exemptDate;
            }
            subTotal = subDays * cyclePrice * (1 - priceRate);
            jdateCount.setText(Formats.INT.formatValue(subDays));
            jcountPrice.setText(Formats.CURRENCY.formatValue(subTotal));
        } catch (BasicException ex) {
            MessageInf msg = new MessageInf(ex);
            msg.show(this);
           jdateCount.setText(Formats.INT.formatValue(0));
           jcountPrice.setText(Formats.CURRENCY.formatValue(0));
        }
     * **/
    }

    @Override
    protected void enterKeyProc() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void escapeKeyProc() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void upKeyProc() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void downKeyProc() {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JButton jcmdCancel;
    private javax.swing.JButton jcmdOK;
    private javax.swing.JTextField jcustomDate;
    private javax.swing.JButton jcustomer;
    private javax.swing.JTextField jcyclePrice;
    private javax.swing.JTextField jexemptDate;
    private javax.swing.JLabel jm_dStartDateLabel;
    private javax.swing.JTextField jpriceRate;
    private javax.swing.JComboBox jrantCycleStyle;
    private javax.swing.JTextField jrantData;
    private javax.swing.JTextField jrantPrice;
    private javax.swing.JButton m_jEnter;
    private javax.swing.JButton m_jEnter1;
    private javax.swing.JButton m_jEnter2;
    private javax.swing.JTextField m_jName;
    private javax.swing.JTextField m_jSearchkey;
    private javax.swing.JTextField m_jTaxID;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtCard;
    private javax.swing.JTextField txtCurdebt;
    private javax.swing.JTextField txtPhone;
    // End of variables declaration//GEN-END:variables

}
